package com.example.sam.zyfypt_414fzh.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.sam.zyfypt_414fzh.R;
import com.example.sam.zyfypt_414fzh.bean.LoginBean;
import com.example.sam.zyfypt_414fzh.iface.LoginListener;
import com.example.sam.zyfypt_414fzh.model.LoginModel;


public class LoginActivity extends AppCompatActivity implements View.OnClickListener {
    private TextView tv1,tvname,tvwe,tvlogin;
    private EditText et1,et2;
    private Button btlogin,btreg;
    private ImageView imv;
    private LoginListener loginListener = new LoginListener() {
        @Override
        public void onResponse(LoginBean loginBean) {
            System.out.println("result:"+loginBean.getId());
            if(loginBean.getId()!=null) {
                Intent intent1 = new Intent(LoginActivity.this, MainActivity.class);
                startActivity(intent1);
            }
        }

        @Override
        public void onFail(String msg) {
            System.out.println("fail");
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        init();
    }
    private void init()
    {
        //获取控件
        tv1=(TextView)findViewById(R.id.textView);
        tvname=(TextView)findViewById(R.id.textView5);
        tvwe=(TextView)findViewById(R.id.textView2);
        tvlogin=(TextView)findViewById(R.id.textView4);
        et1=(EditText)findViewById(R.id.editText);
        et2=(EditText)findViewById(R.id.editText2);
        btlogin=(Button)findViewById(R.id.button);
        btreg=(Button)findViewById(R.id.button2);
        imv=(ImageView)findViewById(R.id.imageView5);

        //设置按钮监听器
        btlogin.setOnClickListener(this);
        btreg.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button:
                System.out.println("点击登陆按钮");
                LoginModel loginModel = new LoginModel();
                loginModel.getResult(et1.getText().toString(), et2.getText().toString(), loginListener);
                break;
                //Intent intent = new Intent(LoginActivity.this, MainActivity.class);
                //startActivity(intent);

            case R.id.button2:
               // Intent intent1 = new Intent(LoginActivity.this, RegisterActivity.class);
               // startActivity(intent1);
                System.out.println("点击注册按钮");
                Intent intent = new Intent();
                intent.setClass(this, RegisterActivity.class);//forward为当前activity，forwardTarget为新的activity
                startActivity(intent);
                break;
        }
    }

}
